package transaction.imp;

import classification.PaymentClassification;
import classification.imp.HourlyClassification;
import dao.PayrollDatabase;
import dao.imp.GpayrollDatabase;
import domain.Employee;
import domain.TimeCard;
import exception.EmployeeException;
import transaction.Transaction;

import java.util.Date;
import java.util.EmptyStackException;

public class TimeCardTransaction implements Transaction {
    private PayrollDatabase payrollDatabase = new GpayrollDatabase();
    private int empid;
    private TimeCard timeCard;
    public TimeCardTransaction(int empid, Date date, double hours) {
        this.timeCard = new TimeCard(date, hours);
        this.empid = empid;
    }

    @Override
    public void execute() throws EmployeeException {
        Employee employee = payrollDatabase.getEmployee(empid);
        if(employee == null) {
            throw new EmployeeException("no such employee where empid = " + empid);
        }

        if(employee.getClassification() instanceof HourlyClassification) {
            HourlyClassification hourlyClassification = (HourlyClassification)employee.getClassification();
            hourlyClassification.addTimeCard(timeCard);
        } else {
            throw new EmployeeException("the employee [" + empid + "] is not hourly employee");
        }

    }
}
